package data

import (
	"log"
	"sync"
)

type APK_INSTALL_STATE int

const (
	NONE   APK_INSTALL_STATE = 0
	FINISH                   = 1
	FAIL                     = 2
)

var (
	OpenDetailLog = true
	LINKER_FLAG   = "@@##"
	// PadApkInstalStateList record apk install status,value:0(prepare to install)  ,1(finish install,may be success or fail)
	PadApkInstalStateList = new(sync.Map)
)

// 将interface{}转换为Color类型
func ToColor(value interface{}) APK_INSTALL_STATE {
	switch v := value.(type) {
	case int:
		if v >= 0 && v < len([]APK_INSTALL_STATE{NONE, FINISH, FAIL}) {
			return APK_INSTALL_STATE(v)
		}
	case APK_INSTALL_STATE:
		return v
	}
	return -1
}

func Test() {
	PadApkInstalStateList.Store("p1", NONE)
	PadApkInstalStateList.Store("p2", FINISH)
	PadApkInstalStateList.Store("p3", FAIL)

	PadApkInstalStateList.Range(func(key, value interface{}) bool {
		log.Printf("key:%s,value:%d", key, ToColor(value))
		//if ToColor(value) > NONE {
		//	log.Printf("key:%s   11111111\n", key)
		//} else {
		//	log.Printf("key:%s   22222222\n", key)
		//}
		return true
	})

}
